#include "applicationinfo.h"
#include "model/friendlistmodel.h"
#include "model/conversationmodel.h"

#include <QApplication>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlEngine>
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickItem>
#include <QUrl>
#include <QQmlApplicationEngine>


static QObject *systeminfo_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
    Q_UNUSED(engine)
    Q_UNUSED(scriptEngine)

    return new ApplicationInfo();
}

void qmlRegister()
{
    qmlRegisterType<ConversationModel>("org.qtproject.qtquick", 1, 0, "ConversationModel");
    qmlRegisterType<FriendListModel>("org.qtproject.qtquick", 1, 0, "FriendListModel");
    qmlRegisterSingletonType<ApplicationInfo>("org.qtproject.qtquick", 1, 0, "ApplicationInfo", systeminfo_provider);
}

int main(int argc, char *argv[])
{
    qmlRegister();

    QApplication app(argc, argv);

    QQmlApplicationEngine engine(QUrl("qrc:/Qml/gui/MainWindow.qml"));
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    if ( !window ) {
        qWarning("Error: Your root item has to be a Window.");
        return -1;
    }
    window->show();
    return app.exec();

}
